import { Table } from 'antd';
import Cls from 'classnames';
import { AssetDiscardContext, IAcquisitionActionEnum } from '../mconfig';
import { useContext, useEffect, useMemo, useState } from 'react';
import { openMaterielColumns } from '../mconfig';
import { getLoadMapList, getSelectDataMapList, getTenantID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';

export const UpdateMaterielView: React.FC<any> = ({ handleMaterialModal, pageType }) => {
  // /**  获取数据字典 */
  const { loadMapInfo, mapLoading } = getLoadMapList([
    `${getTenantID()}${ILoadMapTypeAll.ASSET_TYPE}`, //资产类型
  ]);

  /** 引入上下文 */
  const { materielList, acquisitionDispatch } = useContext(AssetDiscardContext);

  const delSelectRow = (record) => {
    // 取消仓库的选中材料列表
    const arr = materielList.filter((item) => {
      return item.id !== record.id;
    });
    // 更新选中的数据
    acquisitionDispatch({
      type: IAcquisitionActionEnum.SELECT_MATERIEL,
      payload: arr,
    });
  };

  /** 表格行配置 */
  const columns: Record<string, any>[] = useMemo(() => {
    return openMaterielColumns(handleMaterialModal, delSelectRow, pageType);
  }, [materielList]);

  useEffect(() => {}, [materielList]);

  return (
    <div className={Cls('list-table', 'descriptionsType-tableSty')} style={{ marginTop: '10px' }}>
      <Table bordered size="small" dataSource={materielList} columns={columns} rowKey={(res) => res?.id} scroll={{ x: 1200, y: '' }} pagination={false} />
    </div>
  );
};
